package com.zhaogang.transactionManagerDemo.proxy;

import java.math.BigDecimal;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.zhaogang.transactionManagerDemo.entity.SystemLog;
import com.zhaogang.transactionManagerDemo.service.AccountTransactionService;

@Service("AccountTransactionServiceStaticProxy")
public class AccountTransactionServiceStaticProxy implements AccountTransactionService {
	
	@Resource(name="AccountTransactionServiceImpl")
	AccountTransactionService acTranService;
	@Autowired
	private PlatformTransactionManager tm;

	@Override
	public int updateBalanceByAccountNo(String accountNo, BigDecimal amount) {
		return 0;
	}

	@Override
	public void transferSimple(String fromAccountNo, String toAccountNo, BigDecimal amount) {
		TransactionDefinition td = new DefaultTransactionDefinition();
		TransactionStatus ts = tm.getTransaction(td);
		try {
			
			acTranService.transferSimple(fromAccountNo, toAccountNo, amount);	//调用真实主题

			tm.commit(ts);
		} catch (Exception e) {
			tm.rollback(ts);
		}
	}

	@Override
	public void transferSimpleNoTrans(String fromAccountNo, String toAccountNo, BigDecimal amount) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void transfer(String fromAccountNo, String toAccountNo, BigDecimal amount) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public SystemLog addLog(String topic, String tableName, Object old, Object now) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void transferException(String fromAccountNo, String toAccountNo, BigDecimal amount) throws Exception {
		// TODO Auto-generated method stub
		
	}

}
